package com.example.studentstatusmanagement.controller;

import com.example.studentstatusmanagement.config.SystemVariable;
import com.example.studentstatusmanagement.pojo.Major;
import com.example.studentstatusmanagement.pojo.Msg;
import com.example.studentstatusmanagement.pojo.doo.ReqMsg;
import com.example.studentstatusmanagement.pojo.doo.ReqRoom;
import com.example.studentstatusmanagement.pojo.dto.SMsg;
import com.example.studentstatusmanagement.pojo.dto.SRoom;
import com.example.studentstatusmanagement.service.MsgService;
import com.example.studentstatusmanagement.utils.ResultResponse;
import com.example.studentstatusmanagement.utils.ResultTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("api/v1/msg")
@RestController
public class MsgController {

    @Autowired
    private MsgService msgService;

    @RequestMapping("show")
    public Map<String, Object> showDormInfo(ReqMsg reqMsg) {

        Map<String, Object> so = new HashMap<String, Object>();

        List<SMsg> ls = msgService.selectMsgs(reqMsg);

        so.put("code", SystemVariable.URL_SUCCESS);
        so.put("msg", "");
        so.put("count", ls.size());
        so.put("data", ls);

        return so;
    }

    @RequestMapping("del")
    public ResultResponse del(Integer id) {

        if (msgService.deleteByPrimaryKey(id) == SystemVariable.SUCCESS) {
            return ResultResponse.Build(ResultTypeEnum.success, SystemVariable.DO_SUCCESS);
        }
        return ResultResponse.Build(ResultTypeEnum.error, SystemVariable.DO_ERROR);
    }

    @RequestMapping("add")
    public ResultResponse add(Msg msg){

        msg.setCreatetime(new Date());
        if (msgService.insertSelective(msg) == SystemVariable.SUCCESS) {
            return ResultResponse.Build(ResultTypeEnum.success, SystemVariable.DO_SUCCESS);
        }
        return ResultResponse.Build(ResultTypeEnum.error, SystemVariable.DO_ERROR);
    }
}
